//
//  BKMyOrderGetDataFromNetWork.m
//  bestkeep
//
//  Created by Mr. Wu on 16/12/6.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKMyOrderGetDataFromNetWork.h"
#import "BK_OD_Tool.h"
#import "BKMyOrderReturnGoodsModel.h"
#import "BKMyOrderReturnGoodsProgressModel.h"

NSString * const BKMyOrder_strBKAPI = ApplicationEnvironmentProduction ? @"https://api.bestkeep.cn/" :@"https://api.test.bestkeep.cn/" ;

NSString *const API_BK_MyOrder_order_listpage = @"order/listpage";
NSString *const API_BK_MyOrder_order_delOrder = @"order/delOrder";
NSString *const API_BK_MyOrder_order_confirmOrder = @"order/confirmOrder";
NSString *const API_BK_MyOrder_getRecommendGoodsList = @"getRecommendGoodsList";
NSString *const API_BK_MyOrder_orderdetail = @"order/detail/";//订单详情
NSString *const API_BK_MyOrder_Cancelorder = @"order/cancel";//取消订单;
NSString *const API_BK_MyOrder_status_amount = @"order/status-amount";//获取订单各个状态的数量;
NSString *const API_BK_MyOrder_logistics = @"order/logistics-v2";//物流信息;
NSString *const API_BK_MyOrder_waiteEvalute = @"evaluation/evaluationGoodsList";//待评价;
NSString *const API_BK_MyOrder_returnGoods = @"returnGoods/returnGoodsList";//可退换货列表
NSString *const API_BK_MyOrder_returnGoodsprogress = @"returnGoods/returnlist";//退换进度
NSString *const API_BK_MyOrder_returnImage = @"returnGoods/uploadImg";//退换货上传图片
NSString *const API_BK_MyOrder_returnGoodsAll = @"/returnGoods/savereturn";//退换货确认
NSString *const API_BK_MyOrder_split_postage = @"/order/splitExpressAmount";//拆分单邮费请求
NSString *const API_BK_MyOrder_split_pay = @"pay/split-order-express";//拆分单邮费支付
NSString *const API_BK_MyOrder_split_single = @"/order/payedDoSplit";//拆分单

NSString * const BKMyOrder_account_balance = @"account/balance";//查询账户余额
@implementation BKMyOrderGetDataFromNetWork
/*
 * * 
 接口名称：	order_listpage
 接口用途：	分页查询我的订单列表
 */
+(void)GetOrderData:(NSString *)status pagesize:(NSString *)pagesize pageno:(NSString *)pageno Success:(void (^)(NSArray *))sucess failure:(void (^)(NSError *))failure currentPage:(void (^)(NSDictionary *))Page{
    NSString *strURL = [BKMyOrder_strBKAPI stringByAppendingString:API_BK_MyOrder_order_listpage];
    BKMyOrderParamerModel *model = [[BKMyOrderParamerModel alloc]init];
    model.status = status;
    model.pagesize = pagesize;
    model.pageno = pageno;
    
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:strURL parameters:model.mj_keyValues success:^(id  _Nullable responseObject) {
        BOOL success = [[responseObject objectForKey:@"success"] boolValue];
        if (!success){
            NSString *str =[responseObject objectForKey:@"msg"];
            NSDictionary *userInfo = [NSDictionary dictionaryWithObject:str                                                                     forKey:NSLocalizedDescriptionKey];
            NSError *aError = [NSError errorWithDomain:@""code:0 userInfo:userInfo];
            failure(aError);
            return ;
        }
        if (sucess) {
            sucess(responseObject[@"data"][@"rows"]);
            NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:responseObject[@"data"][@"pageno"],@"currentPage", nil];
            Page(dict);
        }
        
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        if (error) {
            failure(error);
        }
    }];
    
}
/*
 * 购物车页面获取推荐商品列表
 */
+(void)GetRecommendGoodsDataFromJsonSucessWithParamer:(NSString *)currentPage Success:(void (^)(NSArray *))sucess failure:(void (^)(NSError *))failure currentPage:(void (^)(NSDictionary *))Page{
    NSString *urlStr = [BKMyOrder_strBKAPI stringByAppendingString:API_BK_MyOrder_getRecommendGoodsList ];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:currentPage,@"currentPage" ,nil];
    
    [[RequestManager manager] bkDataRequest:RequestMethodPost URLString:urlStr parameters:dic success:^(id  _Nullable responseObject) {
        BOOL success = [[responseObject objectForKey:@"success"] boolValue];
        if (!success){
            NSString *str =[responseObject objectForKey:@"msg"];
            NSDictionary *userInfo = [NSDictionary dictionaryWithObject:str                                                                     forKey:NSLocalizedDescriptionKey];
            NSError *aError = [NSError errorWithDomain:@""code:0 userInfo:userInfo];
            failure(aError);
            return ;
        }
        NSArray *array;
        NSMutableArray *CellArray = [NSMutableArray array];//cells数组
        if (sucess) {
            array = [BkMyOrderRecommendModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"list"]];
            for (BkMyOrderRecommendModel*model in array) {
                BK_My_Order_CellModel *recommendModel = [BK_My_Order_CellModel getRecommendGoodsModelWith:model];
                [CellArray addObject:recommendModel];
            };
            sucess(CellArray);
            NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:responseObject[@"data"][@"currentPage"],@"currentPage", nil];
            Page(dict);
        }
        
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        if (failure) {
            failure(error);
        }
        
    }];
}

/*
 * 查询确认收货
 */
+(void)ConfrimReceiveGoodsWithOrderID:(NSString *)OrderID Status:(void (^)(NSString *))Status{
    
    /*
     * 接口名称：	order_confirmOrder
     接口用途：	查询确认收货
     method：	POST
     接口地址：	order/confirmOrder
     输入参数：
     key	参数类型	是否必须	参数解释
     order_id	string	是	订单id
     返回数据：
     {
     "success": "true/false //成功/失败",
     "msg": "xxx //返回消息",
     "code": "xxx //返回编码",
     }
     备注：	
     请求参数：
     order_id:xxxx//订单id
     
     复制
     */
    
    NSString *urlStr = [BKMyOrder_strBKAPI stringByAppendingString:API_BK_MyOrder_order_confirmOrder];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:OrderID,@"order_id" ,nil];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dic success:^(id  _Nullable responseObject) {
        BOOL success   = [[responseObject objectForKey:@"success"] boolValue];
        NSString *str =[responseObject objectForKey:@"msg"];
        
        if (success) {
            Status(@"1");
        }else{
            Status(str);
        }
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        Status(@"确认收货失败");
    }];
    
}
/*
 * 根据订单ID删除订单
 */
+(void)DeleteOrderdataWithOrderID:(NSString *)OrderId Status:(void (^)(NSString *))Status{
    
    /*
     * 接口名称：	_order_delOrder
     接口用途：	根据订单ID删除订单
     method：	POST
     接口地址：	/order/delOrder
     输入参数：
     key	参数类型	是否必须	参数解释
     id	string	是	订单ID
     返回数据：
     {
     "success": "true/false //成功/失败",
     "msg": "xxx //返回消息",
     "code": "xxx //返回编码",
     }
     备注：	
     请求参数：
     id:xxx//订单ID
     */
    
    NSString *urlStr = [BKMyOrder_strBKAPI stringByAppendingString:API_BK_MyOrder_order_delOrder];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:OrderId,@"id" ,nil];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dic success:^(id  _Nullable responseObject) {
        BOOL success   = [[responseObject objectForKey:@"success"] boolValue];
        NSString *str =[responseObject objectForKey:@"msg"];
        
        if (success) {
            Status(@"1");
        }else{
            Status(str);
        }
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        Status(@"删除订单失败");
    }];
    
}

/*
 * 查询订单详情
 */
+(void)GetOrderDetail:(NSString *)OrderID Success:(void (^)(NSArray *))sucess failure:(void (^)(NSError *))failure{
    
    /*
     *
     接口名称：	order_detail_xxx
     接口用途：	查询订单详情
     method：	POST
     接口地址：	order/detail/xxx
     输入参数：	无
     返回数据：
     {
     "success": "true/false //成功/失败",
     "msg": "xxx //返回消息",
     "code": "xxxx//返回编码",
     "data":
     {
     "is_global": "xxxx//是否是全球购订单，1：是，0：否",
     "order_id": "xxx//订单ID",
     "order_no": "xxx//订单编号",
     "order_status": "xxx//订单状态",
     "own_calcle_flag": "xxx//是否可取消订单（1可取消，0不可取消）",
     " order_status_name": "xxx//订单状态名称",
     " deliver_name": "xxx///收货人",
     "deliver_address": "xxx//收货地址",
     " phone": "xxx //收货人手机号，要做打码显示如152****9888",
     " ship_address": "xx//发货地",
     "splitFlag": "xxx//是否显示拆单按钮 1显示，0不显示",
     "canPayTimes": "xx//剩余可支付时间-秒数（只在未支付订单显示）",
     " lastPayTimesStr": "xxx//订单最迟支付时间yyyy-MM-dd HH:mm:ss",
     "evaluationFlag": "xx// 0未评价，1部分评价，2全部已评价",
     "goods_total_amount": "xx.//商品总金额",
     "customs_tax_amount": "xxxx//海关税（全球购的才显示）",
     "express_amount": "xxx//运费",
     "promotion_discount_amount": "xxx//满减优惠金额",
     "order_total_amount": "xxx//订单金额",
     "actualPaymentAmount": "xxx//订单实际支付金额",
     "order_create_time": "xxxx//下单时间",
     "order_pay_time": "xxx//支付时间",
     "order_goods_count": "xxx//订单商品总件数",
     "lastSendDateZh": "xxxx年xx月xx日//预计发货日期",
     "thNormalType": "0/1//是否囤货普通预售，1：是，0：否",
     "order_list":
     [
     {
     "availableDeliver:xx//0": "未到货，1：已到货",
     "itemId": "xxx//子单id",
     " goods_id": "xxx//商品ID",
     " goods_name": "xxx//商品名称",
     "goods_img": "xxx//商品图片",
     "sale_property": "xxx//商品销售属性",
     "goods_price": "xxx//商品单价",
     " goods_amount": "xxx//商品数量",
     "returnFlag": "xx//0:未退换货，1：已退换货",
     "evaluationFlag": "xx// 0未评价，1已评价",
     "plan_deliver_date": "xxxx//预计发货日期",
     }
     ],
     "payAmountDetail":
     [
     {
     " itemName": "xxx //抵扣明细名称(购物券、账户支付等)",
     "itemAmount": "xx //抵扣明细金额",
     " itemAmountStr": "xxx//字符串格式的抵扣明细金额",
     }
     ]
     }
     }
     备注：
     */
    
    NSString *urlStr = [BKMyOrder_strBKAPI stringByAppendingString:API_BK_MyOrder_orderdetail];
    if(!OrderID){
        OrderID = @"";
    }
    
    urlStr = [urlStr stringByAppendingString:OrderID];
    
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:nil success:^(id  _Nullable responseObject) {
        BOOL success = [[responseObject objectForKey:@"success"] boolValue];
        if (!success){
            NSString *str =[responseObject objectForKey:@"msg"];
            NSDictionary *userInfo = [NSDictionary dictionaryWithObject:str                                                                     forKey:NSLocalizedDescriptionKey];
            NSError *aError = [NSError errorWithDomain:@""code:0 userInfo:userInfo];
            failure(aError);
            return ;
        }
        if (sucess) {
            BK_My_DetailOrder_Model *model = [BK_My_DetailOrder_Model mj_objectWithKeyValues:responseObject[@"data"]];
            NSArray *array = [BK_My_DetailOrder_SectionModel CreateOrderSectionWithArray:model];
            sucess(array);
        }
        
    }  failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        failure(error);
    }];
}

/*
 * 用户取消订单
 */
+(void)CancelOrder:(NSString *)Order_id reason:(NSString *)reason Status:(void (^)(NSString *))Status{
    
    
    /*
     *
     接口名称：	order_cancel
     接口用途：	用户取消订单
     method：	POST
     接口地址：	order/cancel
     输入参数：
     key	参数类型	是否必须	参数解释
     order_id	string	是	订单id
     cancel_reason	string	是	取消理由
     返回数据：
     {
     "success": "true/false //成功/失败",
     "msg": "xxx //返回消息",
     "code": "xxx //返回编码",
     }
     备注：
     请求参数： order_id:xxxx//订单id cancel_reason:取消理由
     
     复制
     */
    NSString *urlStr = [BKMyOrder_strBKAPI stringByAppendingString:API_BK_MyOrder_Cancelorder];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:Order_id,@"order_id",reason,@"cancel_reason",nil];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dic success:^(id  _Nullable responseObject) {
        BOOL success   = [[responseObject objectForKey:@"success"] boolValue];
        NSString *str =[responseObject objectForKey:@"msg"];
        
        if (success) {
            Status(@"1");
        }else{
            Status(str);
        }
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        Status(error.localizedDescription);
        
    }];
    
    
}

/*
 * 显示订单各个状态数量
 */
+(void)GetOrderStausSuccess:(void (^)(id))sucess failure:(void (^)(NSError *))failure{
    
    /*
     * 接口名称：	order_status-amount
     接口用途：	显示订单各个状态数量
     method：	POST
     接口地址：	order/status-amount
     输入参数：	无
     返回数据：
     {
     "success": "true/false //成功/失败",
     "msg": "xxx //返回消息",
     "code": "xxx //返回编码",
     "data":
     {
     "wait_pay": "xxx//待付款",
     "paid": "xxx//待发货",
     "wait_receive": "xxx//待收货",
     "wait_evaluation": "xxx 待评价商品数量",
     "wait__evaluation_order": "xxx//待评价订单数量",
     }
     }
     备注：
     */
    
    
    NSString *urlStr = [BKMyOrder_strBKAPI stringByAppendingString:API_BK_MyOrder_status_amount];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:nil success:^(id  _Nullable responseObject) {
        BOOL success   = [[responseObject objectForKey:@"success"] boolValue];
        if (success) {
            BKMyOrderStatusCount *model = [BKMyOrderStatusCount mj_objectWithKeyValues:responseObject[@"data"]];
            
            sucess(model);
        }
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        failure(error);
    }];
    
    
}

/*
 * 查询订单物流信息数据
 */
+(void)GetOrderLogisticsWithOrderno:(NSString *)order_no Success:(void (^)(id))sucess failure:(void (^)(NSError *))failure{
    /*
     * 接口名称：	order_logistics-v2
     接口用途：	查询订单物流信息数据
     method：	POST
     接口地址：	order/logistics-v2
     输入参数：
     key	参数类型	是否必须	参数解释
     order_no	int	是	订单号
     返回数据：
     {
     "success": "true/false //成功/失败",
     "msg": "xxx //返回消息",
     "code": "xxxx//返回编码",
     "data":
     {
     "":
     [
     {
     "express_compnay": "xxxx//物流公司",
     " express_no": "xxx//运单号",
     " logistics_data":
     [
     {
     "remark": "xxx//物流备注",
     "time": "xxx//物流时间",
     }
     ]
     }
     ]
     }
     }
     备注：
     请求参数：
     order_no://订单号
     
     data中包含多个物流公司，是一个JSON数组
     */
    NSString *urlStr = [BKMyOrder_strBKAPI stringByAppendingString:API_BK_MyOrder_logistics];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:order_no,@"order_no",nil];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dic success:^(id  _Nullable responseObject) {
        //BOOL success   = [[responseObject objectForKey:@"success"] boolValue];
        NSDictionary *dic = [[NSDictionary alloc]initWithDictionary:responseObject];
        
        sucess(dic);
        
        
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        failure(error);
    }];
    
    
}

/*
 * 获取订单评价商品列表
 */
+(void)GetOrderEvalutingCount:(NSString *)evaluationFlag OrderId:(NSString *)OrderId pagesize:(NSString *)pagesize pageno:(NSString *)pageno Success:(void (^)(NSArray *))sucess failure:(void (^)(NSError *))failure currentPage:(void (^)(NSDictionary *))Page{
    
    /*
     *
     接口名称：	evaluation_evaluationGoodsList
     接口用途：	获取订单评价商品列表
     method：	POST
     接口地址：	evaluation/evaluationGoodsList
     输入参数：
     key	参数类型	是否必须	参数解释
     evaluationFlag	int	是	评价标识（0:未评价，1：已评价）
     orderId	string	是	订单id(空值表示全部订单的)
     pageNo	int	是	当前第几页
     pageSize	int	是	显示多少条
     返回数据：
     {
     "resultCode": "1, //结果代码",
     "success": "true/false //成功或失败",
     "data":
     {
     " total": "xxx//记录总条数",
     " list":
     [
     {
     "evaluationFlag": "xxx,//商品评价标识",
     " goodsId": "xxx,//商品Id",
     "goodsImg": "xxx,//商品图片路径",
     "goodsName": "xxx,//商品名称",
     "goodsNo": "xxx,//商品编号",
     "goodsReserveId": "xxx,//商品库存Id",
     "goodsSnapId": "xxx",
     " orderId": "xxx,//订单Id",
     " orderItemId": "xxx//订单子项表Id",
     "goodsPrRel": "//商品销售参数",
     "":
     [
     {
     "proName": "xxx,//参数名称",
     " proValue": "xxx,//参数值",
     "relImg": "xxx//参数图片",
     }
     ]
     }
     ]
     }
     }
     备注：
     请求参数：
     evaluationFlag:xxx//评价标识（0:未评价，1：已评价） orderId:xxx//订单id(空值表示全部订单的) pageNo:xxx当前第几页 pageSize:xx//显示多少条
     */
    NSString *urlStr = [BKMyOrder_strBKAPI stringByAppendingString:API_BK_MyOrder_waiteEvalute];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:evaluationFlag,@"evaluationFlag",OrderId,@"orderId", pageno,@"pageNo" ,pagesize,@"pageSize", nil];

    [[RequestManager manager] bkDataRequest:RequestMethodPost URLString:urlStr parameters:dic success:^(id  _Nullable responseObject) {
        BOOL success = [[responseObject objectForKey:@"success"] boolValue];
        if (!success){
            
            NSString *str =[responseObject objectForKey:@"msg"];
            NSDictionary *userInfo = [NSDictionary dictionaryWithObject:str                                                                     forKey:NSLocalizedDescriptionKey];
            NSError *aError = [NSError errorWithDomain:@""code:0 userInfo:userInfo];
            
            failure(aError);
            
            return ;
            
        }
        if (sucess) {
            NSArray *array  = [BKMyOrderEvalutingCountModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"list"]];
            sucess(array);
            NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:responseObject[@"data"][@"total"],@"total", nil];
            Page(dict);
        }
        
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        if (failure) {
            failure(error);
            
        }
        
    }];
    
}

/*
 * 分页查询可退换货列表
 */
+(void)GetOrderReturnGoodsPagesize:(NSString *)pagesize pageno:(NSString *)page_no Success:(void (^)(NSArray *))sucess failure:(void (^)(NSError *))failure currentPage:(void (^)(NSDictionary *))Page{
    
    /*
     *
     接口名称：	returnGoods_returnGoodsList
     接口用途：	分页查询可退换货列表
     method：	POST
     接口地址：	returnGoods/returnGoodsList
     输入参数：
     key	参数类型	是否必须	参数解释
     pagesize	int	是	显示多少条
     pageno	int	是	当前第几页
     返回数据：
     {
     "success": "true/false //成功/失败",
     "msg": "xxx //返回消息",
     "code": "xxx //返回编码",
     "data":
     {
     "total": "xxx//总记录数",
     "pageno": "xxx//当前第几页",
     "pagesize": "xxx//每个显示多少条",
     "list":
     [
     {
     "order_no": "xxx//订单编号",
     "order_list":
     [
     {
     "itemId": "xxx,//订单子项id",
     "goods_name": "xxx//商品名称",
     "goods_img": "xxx//图片",
     "goods_amount": "xxx//数量",
     "order_create_time": "xxx//下单时间",
     "ship_address": "xxx//发货地址",
     " propList":
     [
     {
     "name": "xxx//属性名称",
     "value": "xxx//属性值",
     }
     ]
     }
     ]
     }
     ]
     }
     }
     备注：
     请求参数：
     pagesize:xx//显示多少条 pageno:xxx当前第几页
     
     复制
     */
    NSString *urlStr = [BKMyOrder_strBKAPI stringByAppendingString:API_BK_MyOrder_returnGoods];
    NSDictionary *boby_dic =[NSDictionary dictionaryWithObjectsAndKeys:pagesize,@"pagesize",page_no,@"pageno", nil];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:boby_dic success:^(id  _Nullable responseObject) {
        BOOL success = [[responseObject objectForKey:@"success"] boolValue];
        if (!success){
            
            NSString *str =[responseObject objectForKey:@"msg"];
            NSDictionary *userInfo = [NSDictionary dictionaryWithObject:str                                                                     forKey:NSLocalizedDescriptionKey];
            NSError *aError = [NSError errorWithDomain:@""code:0 userInfo:userInfo];
            
            failure(aError);
            
            return ;
            
        }
        NSArray *array;
        
        if (sucess) {
            array = [BKMyOrderReturnGoodsModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"list"]];
            sucess(array);
            NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:responseObject[@"data"][@"pageno"],@"pageno",responseObject[@"data"][@"total"],@"total", nil];
            Page(dict);
        }
        
        
        
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        if (failure) {
            NSLog(@"%d",error.code);
            
            failure(error);
        }
    }];
    
    
}


/*
 * 我的退换货列表
 */
+(void)GetOrderReturnGoodsProgress:(NSString *)pagesize pageno:(NSString *)page_no Success:(void (^)(NSArray *))sucess failure:(void (^)(NSError *))failure currentPage:(void (^)(NSDictionary *))Page{
    /*
     * 接口名称：	returnGoods_returnlist
     接口用途：	我的退换货列表
     method：	POST
     接口地址：	returnGoods/returnlist
     输入参数：
     key	参数类型	是否必须	参数解释
     pagesize	int	是	显示多少条
     pageno	int	是	当前第几页
     返回数据：
     {
     "success": "true/false //成功/失败",
     "msg": "xxx //返回消息",
     "code": "xxx //返回编码",
     "data":
     {
     "total": "xxx//总记录数",
     "pageno": "xxx//当前第几页",
     "pagesize": "xxx//每个显示多少条",
     " list":
     [
     {
     "id": "xxx,//退换货单id",
     "goodsName": "xxx//商品名称",
     "goodsImg": "xxx//退换货申请图片",
     "itemGoodsImg": "xxx//商品图片",
     "createdDateStr": "xxx//申请时间",
     "statusFlag": "xx//0:未拒绝，1：审核拒绝（失败）",
     "status:xx//06": "审核通过，08：已完成，其他：审核中",
     }
     ]
     }
     }
     备注：
     请求参数：
     pagesize:xx//显示多少条 pageno:xxx当前第几页
     
     statusFlag是1直接显示审核不通过
     */
    
    NSString *urlStr = [BKMyOrder_strBKAPI stringByAppendingString:API_BK_MyOrder_returnGoodsprogress];
    NSDictionary *boby_dic =[NSDictionary dictionaryWithObjectsAndKeys:pagesize,@"pagesize",page_no,@"pageno", nil];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:boby_dic success:^(id  _Nullable responseObject) {
        BOOL success = [[responseObject objectForKey:@"success"] boolValue];
        if (!success){
            
            NSString *str =[responseObject objectForKey:@"msg"];
            NSDictionary *userInfo = [NSDictionary dictionaryWithObject:str                                                                     forKey:NSLocalizedDescriptionKey];
            NSError *aError = [NSError errorWithDomain:@""code:0 userInfo:userInfo];
            
            failure(aError);
            
            return ;
            
        }
        NSArray *array;
        
        if (sucess) {
            array = [BKMyOrderReturnGoodsProgressModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"list"]];
            sucess(array);
            NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:responseObject[@"data"][@"pageno"],@"pageno",responseObject[@"data"][@"total"],@"total", nil];
            Page(dict);
        }
        
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        if (failure) {
            failure(error);
        }
    }];
    
    
}


/*
 * 退换货上传图片
 */
+(void)uploadImage:(NSData *)imageData imageName:(NSString *)imageName Success:(void (^)(id))sucess failure:(void (^)(NSError *))failure{
    
    /*
     *
     接口名称：	returnGoods_uploadImg
     接口用途：	退换货上传图片
     method：	POST
     接口地址：	/returnGoods/uploadImg
     输入参数：
     key	参数类型	是否必须	参数解释
     picture	file	是	文件类型
     返回数据：
     {
     "success": "true/false //成功/失败",
     "msg": "xxx //返回消息",
     "code": "xxx //编码",
     "urls": "xxx//图片路径",
     }
     备注：	
     请求参数： picture:xx//文件类型
     */
    
    NSString *urlStr = [BKMyOrder_strBKAPI stringByAppendingString:API_BK_MyOrder_returnImage];
    BKFileObject *file = [[BKFileObject alloc] init];
    file.name = @"picture";
    file.fileName = @"image.jpg";
    file.data = imageData;
    [[RequestManager manager] bkUploadRequest:RequestMethodPost URLString:urlStr parameters:nil file:file success:^(id  _Nullable responseObject) {
        if (responseObject) {
            NSDictionary * dataDict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            
            if (sucess) {
                sucess(dataDict);
                
            }
        }
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        if (failure) {
            failure(error);
            
        }
    }];
    
    
    
}


/*
 * 退换货
 */
+(void)OrderReturnGoodsDic:(NSDictionary *)dic Status:(void (^)(NSString *))Status{
    
    
    /*
     *
     接口名称：	returnGoods_savereturn
     接口用途：	退换货
     method：	POST
     接口地址：	/returnGoods/savereturn
     输入参数：
     key	参数类型	是否必须	参数解释
     orderItemId	string	是	订单子项id
     goodsImgs	string	是	上传图片的路径，多个用逗号分隔
     returnreason	string	是	退换货理由
     returntype	int	是	退换货类型（1：退货，2：换货）
     返回数据：
     {
     "success": "true/false //成功/失败",
     "msg": "xxx //返回消息",
     "errorCode": "xxx //返回错误编码",
     "errorMsg": "xxx//错误信息",
     }
     备注：
     请求参数： orderItemId:xxx//订单子项id， goodsImgs:xxx//上传图片的路径，多个用逗号分隔， returnreason:xxx//退换货理由， returntype:xxx//退换货类型（1：退货，2：换货）
     
     复制
     
     */
    NSString *urlStr = [BKMyOrder_strBKAPI stringByAppendingString:API_BK_MyOrder_returnGoodsAll];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dic success:^(id  _Nullable responseObject) {
        BOOL success   = [[responseObject objectForKey:@"success"] boolValue];
        NSString *str =[responseObject objectForKey:@"msg"];
        
        if (success) {
            Status(@"1");
        }else{
            Status(str);
        }
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        Status(error.localizedDescription);
        
    }];
  
    
}


/*
 * 分单邮费计算
 */
+(void)splitOrderGetPostageWithDic:(NSDictionary *)dic Success:(void (^)(NSString *))sucess failure:(void(^)(NSError *error))failure{
    
    /*
     *
     接口名称：	order_splitExpressAmount
     接口用途：	分单邮费计算
     method：	POST
     接口地址：	/order/splitExpressAmount
     输入参数：
     key	参数类型	是否必须	参数解释
     order_no	int	是	订单编号
     itemIds	string	是	选择的要拆单的子单id，多个用逗号分隔
     返回数据：
     {
     "success": "true/false //成功/失败",
     "msg": "xxx //返回消息",
     "errorCode": "xxx //返回错误编码",
     "data":
     {
     "amount": "xxx//邮费金额",
     }
     }
     备注：
     请求参数：
     order_no:xxx//订单编号， itemIds:xxx//选择的要拆单的子单id，多个用逗号分隔
     
     复制
     
     */
     NSString *urlStr = [BKMyOrder_strBKAPI stringByAppendingString:API_BK_MyOrder_split_postage];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dic success:^(id  _Nullable responseObject) {
        BOOL success = [[responseObject objectForKey:@"success"] boolValue];
        if (!success){
            
            NSString *str =[responseObject objectForKey:@"msg"];
            NSDictionary *userInfo = [NSDictionary dictionaryWithObject:str                                                                     forKey:NSLocalizedDescriptionKey];
            NSError *aError = [NSError errorWithDomain:@""code:0 userInfo:userInfo];
            
            failure(aError);
            return ;
        }
        if (success) {
             NSString *money = responseObject[@"data"][@"amount"];
            sucess(money);
        }
            } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        if (failure) {
            failure(error);
        }
    }];
   
}

/*
 * 分单
 */
+(void)splitOrderWithDic:(NSDictionary *)dic Status:(void (^)(NSString *))Status{
    
    /*
     *
     接口名称：	order_payedDoSplit
     接口用途：	分单
     method：	POST
     接口地址：	/order/payedDoSplit
     输入参数：
     key	参数类型	是否必须	参数解释
     order_no	int	是	订单编号
     itemIds	string	是	选择的要拆单的子单id，多个用逗号分隔
     返回数据：
     {
     "success": "true/false //成功/失败",
     "msg": "xxx //返回消息",
     "errorCode": "xxx //返回错误编码",
     }
     备注：
     请求参数：
     order_no:xxx//订单编号， itemIds:xxx//选择的要拆单的子单id，多个用逗号分隔
     
     复制
     */
    NSString *urlStr = [BKMyOrder_strBKAPI stringByAppendingString:API_BK_MyOrder_split_single];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dic success:^(id  _Nullable responseObject) {
        BOOL success = [[responseObject objectForKey:@"success"] boolValue];
        if (!success){
              NSString *str =[responseObject objectForKey:@"msg"];
            Status(str);
        }
        if (success) {
            Status(@"1");
        }
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        Status(error.localizedDescription);
            }];
}
/*
 * 查询账户信息
 */
+(void)accountMoneyInfoSuccess:(void (^)(id))sucess failure:(void (^)(NSError *))failure{
    
    /*
     *
     接口名称：	account_balance
     接口用途：	查询账户信息
     method：	POST
     接口地址：	/account/balance
     输入参数：	无
     返回数据：
     {
     "success": "true/false //成功/失败",
     "msg": "xxx //返回消息",
     "errorCode": "xxx //返回错误编码",
     "data":
     {
     "account":
     [
     {
     "account_balance": "xxx//账户余额",
     "account_type": "xxx//账户类型(001 财富账户，002 申购金账户，012 糖罐账户)",
     "account_type_name": "xxx//账户类型名称 (申购金账户和财富账户)如果是非会员用户直接显示账户余额，且只有申购金账户注意如果是糖罐账户返回的是人民币，但是界面得显示颗，一元=10颗糖",
     }
     ],
     "is_full_member": "0/1 //是否是会员 1:是会员 0：非会员",
     }
     }
     备注：
     */
    NSString *urlStr = [BKMyOrder_strBKAPI stringByAppendingString:BKMyOrder_account_balance];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:nil success:^(id  _Nullable responseObject) {
        BOOL success = [[responseObject objectForKey:@"success"] boolValue];
        if (!success){
            
            NSString *str =[responseObject objectForKey:@"msg"];
            NSDictionary *userInfo = [NSDictionary dictionaryWithObject:str                                                                     forKey:NSLocalizedDescriptionKey];
            NSError *aError = [NSError errorWithDomain:@""code:0 userInfo:userInfo];
            
            failure(aError);
            
            return ;

            
        }
        if (success) {
            NSDictionary *data_dic =[responseObject objectForKey:@"data"];
            sucess(data_dic);
        }
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        failure(error);
    }];

    
}


/*
 * 提交付款信息   拆分单邮费支付
 */
+(void)splitToPayPostageWithDic:(NSDictionary *)dic Success:(void (^)(NSString *))sucess failure:(void (^)(NSError *))failure{
    
    /*
     *
     接口名称：	pay_split-order-express
     接口用途：	提交付款信息
     method：	POST
     接口地址：	pay/split-order-express
     输入参数：
     key	参数类型	是否必须	参数解释
     order_no	int	是	订单号
     order_item_ids	string	是	订单子项ID, 多个以英文逗号分隔
     account_type	int	是	001/002账户类型code
     返回数据：
     {
     "success": "true/false //成功/失败",
     "msg": "xxx //返回消息",
     "code": "xxx //返回编码",
     }
     备注：
     请求参数： order_no:xxx//订单号 order_item_ids:xxxx//订单子项ID, 多个以英文逗号分隔 account_type=001/002账户类型code
     */
    NSString *urlStr = [BKMyOrder_strBKAPI stringByAppendingString:API_BK_MyOrder_split_pay];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dic success:^(id  _Nullable responseObject) {
        BOOL success = [[responseObject objectForKey:@"success"] boolValue];
        if (!success){
            
            NSString *str =[responseObject objectForKey:@"msg"];
            NSDictionary *userInfo = [NSDictionary dictionaryWithObject:str                                                                     forKey:NSLocalizedDescriptionKey];
            NSError *aError = [NSError errorWithDomain:@""code:0 userInfo:userInfo];
            
            failure(aError);
            return ;
        }
        if (success) {
            
            sucess(@"1");
        }
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        if (failure) {
            failure(error);
        }
    }];

}

@end
